package edu.jmu.bean.user;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
 * 机构实体
 * @author Neal
 *
 */
@Entity
@Table(name="T_BRANCH")
public class Branch implements Serializable{
	/**
	 *  
	 */
	private static final long serialVersionUID = 8211392603344720575L;
	/** 主键   **/
	private Integer id;
	/** 机构名称   **/
	private String name;
	/** 机构简称  **/
	private String shotName;
	/**	下属部门	**/
	private Set<Depart> departs = new HashSet<Depart>();
	@Id	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=50,nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(length=50,nullable=false)
	public String getShotName() {
		return shotName;
	}
	public void setShotName(String shotName) {
		this.shotName = shotName;
	}
	@OneToMany(cascade=CascadeType.PERSIST,mappedBy="branch")
	public Set<Depart> getDeparts() {
		return departs;
	}
	public void setDeparts(Set<Depart> departs) {
		this.departs = departs;
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Branch other = (Branch) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
